<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>列表</title>
    <script src="../../js/vue.js"></script>
</head>

<body>
    <div id="root">
        <!-- 遍历数据 -->
        <button @click.once="addPerson">增加</button>
        <ul>
            <li v-for="(p,index) in persons" :key="p.id">
                {{p.name}}-{{p.age}}
                <input type="text">
            </li>
        </ul>

    </div>


    <script>
        Vue.config.productionTip = false;
        new Vue({
            el: '#root',
            data: {
                persons: [
                    { id: '001', name: "张三", age: 32 },
                    { id: '002', name: "李四", age: 35 },
                    { id: '003', name: "王五", age: 5 }
                ]
            },
            methods: {
                addPerson() {
                    const p = { id: '004', name: "赵六", age: 40 }
                    this.persons.unshift(p);
                }
            }
        })
    </script>

</body>

</html>